window.onload = function (){
    var houseid;
    to_page(1);
}

function to_page(pageNum){
    $.ajax({
        url:"userHouse",
        data: {
            "startPage":pageNum
        },
        dataType:"json",
        success:function (data){
            showPage(data.pageNum,data.totalPage);
            showall(data);
        }
    })
}

function showall(data){
    $("#father").empty();
    $("#page").empty();
    let result = "";
    let result2 = "";
    for (let tr of data.data){
        result = "<TR>"+
            "<TD class=house-thumb>"+
            "<SPAN>"+
            "<A href='details.htm' target='_blank'>"+
            "<img src='../images/thumb_house.gif' width='100' height='75' alt=''>"+
            "</A>"+
            "</SPAN>"+
            "</TD>"+
            "<TD>"+
            "<DL>"+
            "<DT><A href='' onclick='tz("+tr.hid+")' target='_blank'><span>"+tr.title+"</span></A></DT>"+
            "<DD>"+tr.townModel.townname+tr.streetModel.sname+","+tr.area+"平米<BR>联系方式："+tr.phone+"</DD>"+
            "</DL>"+
            "</TD>"+
            "<TD class=house-type><LABEL class=ui-green><INPUT onclick='tz2("+tr.hid+")' value='修    改' type=button name=search></LABEL></TD>"+
            "<TD class=house-price><LABEL class=ui-green><INPUT onclick='del("+tr.hid+")' value='删    除' type=button name=search></LABEL></TD>"+
            "</TR>";
        $("#father").append(result);
    }

    result2 = "<LI>"+
        "<A href='#' id='prev' onclick='prev("+data.pageNum+")'>上一页</A>"+
        "</LI>"+
        "<LI>"+
        "<A href='#' id='next' onclick='next("+data.pageNum+")' >下一页</A>"+
        "</LI>";
    $("#page").append(result2);



        // "<LI class=current>"+
        // "<A id='perv' parseContent='true' showError='true' targets='houseArea' ajaxAfterValidation='false' validate='false' dojoType='struts:BindAnchor'>1</A>"+
        // "</LI>"+
        // "<LI class=current>"+
        // "<A id='next' parseContent='true' showError='true' targets='houseArea' ajaxAfterValidation='false' validate='false' dojoType='struts:BindAnchor'>2</A>"+
        // "</LI>";
}

function showPage(pageNum,totalPage){
    $("#pageNum").empty();
    $("#totalPage").empty();
    $("#pageNum").html(pageNum);
    $("#totalPage").html(totalPage);
}

function prev(pageNum){
    to_page(pageNum-1);
}
function next(pageNum){
    to_page(pageNum+1);
}

function del(id){
    $.post({
        url:"delHouse",
        type:"post",
        data:{
          id:id
        },
        dataType:"json",
        success:function (data){
            alert(data.msg);
            location.reload();
        }

    })
}

function tz(id){
    sessionStorage.setItem("houseid",id);
    location.href = "details.htm";
}

function tz2(id){
    sessionStorage.setItem("hid",id);
    location.href = "update.htm";
}